package com.example.homegroup.seckill.view;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.homegroup.BR;
import com.example.homegroup.R;
import com.example.homegroup.databinding.ActivitySeckollValuesBinding;
import com.example.homegroup.seckill.data.entity.SecKillEntity;
import com.example.homegroup.seckill.service.SecKillService;
import com.example.homegroup.seckill.viewmodel.SeckollValuesViewModel;
import com.example.loadimage.LoadImage;
import com.example.mvvmcommon.mvvm.view.BaseActivity;

import io.reactivex.annotations.Nullable;


@Route(path = "/homegroup/seckillvaluesactivity")
public class SeckollValuesActivity extends BaseActivity<ActivitySeckollValuesBinding, SeckollValuesViewModel> {

    private SecKillService.SecKillBind bind;
    private LinearLayout llBottom;
    private ImageView img;
    private TextView tv1;
    private TextView tv2;
    private TextView mSkuLabelTv;
    private TextView mSkuSelectedTv;
    private ImageView mMoreIv;

    @Override
    protected boolean isFullScreen() {
        return false;
    }

    @Override
    protected int initVariable() {
        return BR.vm;
    }

    @Override
    protected int setColor() {
        return R.color.common_blue;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_seckoll_values;
    }

    @Override
    protected void onResume() {
        super.onResume();
        Intent intent = new Intent(this, SecKillService.class);
        bindService(intent, connection, BIND_AUTO_CREATE);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unbindService(connection);
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        Bundle bundle = getIntent().getExtras();
        SecKillEntity.Value value = (SecKillEntity.Value) bundle.getSerializable("value");
        vm.value = value;
        int goods_num = value.goods_num;
        String goods_desc = value.goods_desc;
        String goods_default_icon = value.goods_default_icon;
        String goods_default_sku = value.goods_default_sku;
        tv1.setText(goods_num+"");
        tv2.setText(goods_desc);
        mSkuLabelTv.setText(goods_default_sku);
        LoadImage.loadImg(goods_default_icon,img);
    }

    private ServiceConnection connection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            bind = (SecKillService.SecKillBind) service;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };


    private void initView() {
        llBottom = (LinearLayout) findViewById(R.id.ll_bottom);
        img = (ImageView) findViewById(R.id.img);
        tv1 = (TextView) findViewById(R.id.tv1);
        tv2 = (TextView) findViewById(R.id.tv2);
        mSkuLabelTv = (TextView) findViewById(R.id.mSkuLabelTv);
        mSkuSelectedTv = (TextView) findViewById(R.id.mSkuSelectedTv);
        mMoreIv = (ImageView) findViewById(R.id.mMoreIv);
    }
}